/*
 * ThermistorParamsPanel.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   ThermistorParamsPanel.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   11 sep 2012
 */

#ifndef THERMISTORPARAMSPANEL_HPP
#define THERMISTORPARAMSPANEL_HPP

#include <wx/wx.h>
#include <wx/grid.h>
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>

#include "TemperatureScale.hpp"
#include "ThermistorModel.hpp"
#include "ThermistorTable.hpp"
#include "ThermistorTableRow.hpp"

using boost::shared_ptr;

namespace tltgen {

  class ThermistorParamsPanel : public wxPanel {
  public:
    ThermistorParamsPanel(wxWindow* parent, wxWindowID id, const shared_ptr<ThermistorTable>& thermistorTable, const shared_ptr<LeastSquaresSolver>& solver, const shared_ptr<TemperatureScale>& temperatureScale, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL);
    virtual ~ThermistorParamsPanel();

    static bool isValidThermistorTable(const shared_ptr<ThermistorTable>& thermistorTable);
    static bool isValidLeastSquaresSolver(const shared_ptr<LeastSquaresSolver>& leastSquaresSolver);
    static bool isValidTemperatureScale(const shared_ptr<TemperatureScale>& temperatureScale);

    virtual shared_ptr<TemperatureScale> getTemperatureScale() const;
    virtual void setTemperatureScale(const shared_ptr<TemperatureScale>& temperatureScale);

    virtual void addThermistorModel(const shared_ptr<ThermistorModel>& thermistorModel);
    
    virtual shared_ptr<ThermistorTable> getThermistorTable() const;
    virtual shared_ptr<LeastSquaresSolver> getLeastSquaresSolver() const;
    

  protected:
    DECLARE_EVENT_TABLE();
    virtual void addThermistorModelPanel(const shared_ptr<ThermistorModel>& thermistorModel);
    virtual void onThermistorTableChanged(ThermistorTable::Event e, ThermistorTableRow* row);

    virtual void updateValues();
    virtual void updateValues(const shared_ptr<ThermistorModel>& thermistorModel, const std::vector<wxTextCtrl*>& txtCtrls);

    wxString formatValue(double v, ThermistorModel::ParameterType type) const;

    boost::unordered_map<shared_ptr<ThermistorModel>, std::vector<wxTextCtrl*> > thermistorModelMap;

    shared_ptr<ThermistorTable> thermistorTable;
    shared_ptr<LeastSquaresSolver> leastSquaresSolver;
    shared_ptr<TemperatureScale> temperatureScale;
  };


}

#endif
